package uml.controller;

import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JFrame;

import uml.GUI.MainWindow;
import uml.eventsystem.IObserver;
import uml.eventsystem.events.UMLEventId;
import uml.objects.UMLObject;
import uml.view.ClassFormatter_View;
import uml.view.factory.ClassFormatterFactory;
import uml.view.factory.RelationshipArrowFactory;

/**
 * 
 * @author Ricardo Myers
 * @author James Feather
 *
 */
public class Controller implements IObserver
{
	//private Collection<Object[]> m_Container;
	private List<UMLObject> m_selectedObjects = new LinkedList<UMLObject>();
	private ArrayList<UMLObject> m_umlObjects = new ArrayList<UMLObject>();
	MainWindow m_window = new MainWindow(this);
	
	/**
	 * Default contructor - this will setup the main window with a 
	 * default title bar and GUI.
	 */
	public Controller()
	{
		
	}
	
	/**
	 * adds UMLObject to the hashMap.
	 * @param newObject
	 * @author James Feather
	 */
	public void add(UMLObject newObject)
	{
		m_umlObjects.add(newObject);
		synchronized(newObject.getTreeLock())
		{
			m_window.addObject(newObject);
		}
	}
	
	/**
	 * removes the UMLObject with ID from the hash map.  If the object does not exist it does nothing.
	 * @param umlId
	 * @author James Feather
	 */
	public void remove(UMLObject object)
	{
		m_umlObjects.remove(object);
		m_window.remove(object);
	}
	
	@Override
	public void handleNotification (UMLEventId eventId)
	{
		UMLObject formatter;
		switch(eventId){
		case APPLICATION_EXIT:
			m_window.dispose();
			System.exit(0);
			break;
		default:
			formatter = ClassFormatterFactory.createObject (eventId);
			m_window.addObject(formatter);
			this.add (formatter);		
		}
	}
}
